package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.appcommon.entity.CommonList;
import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.di.scope.ActivityScope;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.entity.Bank;
import com.chainyoung.component_tmperson.entity.PurseAddr;
import com.chainyoung.component_tmperson.entity.RechargeRecord;
import com.chainyoung.component_tmperson.ui.mvp.contract.RechargeRecordContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.WalletAddrContract;

import java.util.ArrayList;
import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;

@ActivityScope
public class RechargeRecordPresenter  extends BasePresenter<RechargeRecordContract.Model, RechargeRecordContract.View> {


    @Inject
    public RechargeRecordPresenter(RechargeRecordContract.Model model, RechargeRecordContract.View rootView) {
        super(model, rootView);
    }


//    public void getRechargeRecord(TreeMap<String, Object> map) {
//        addSubscribe(mModel.getRechargeRecord(map)
//                .compose(RxUtils.<CommonList<RechargeRecord>>rxSchedulerHelper())
//                .subscribeWith(new CommonSubscriber<CommonList<RechargeRecord>>(mView) {
//                    @Override
//                    public void onNext(CommonList<RechargeRecord> data) {
//                        mView.onGetRechargeRecordSuccess(data);
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        if (e instanceof ApiException){
//                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)){
//                                mView.onGetRechargeRecordSuccess(null);
//                            }
//                            return;
//                        }
//                        mView.onGetRechargeRecordFailed();
//                        super.onError(e);
//                    }
//                }));
//    }


//    public void getCashRecord(TreeMap<String, Object> map) {
//        addSubscribe(mModel.getCashRecord(map)
//                .compose(RxUtils.<CommonList<RechargeRecord>>rxSchedulerHelper())
//                .subscribeWith(new CommonSubscriber<CommonList<RechargeRecord>>(mView) {
//                    @Override
//                    public void onNext(CommonList<RechargeRecord> data) {
//                        mView.onGetRechargeRecordSuccess(data);
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        if (e instanceof ApiException){
//                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)){
//                                mView.onGetRechargeRecordSuccess(null);
//                            }
//                            return;
//                        }
//                        mView.onGetRechargeRecordFailed();
//                        super.onError(e);
//                    }
//                }));
//    }

    public void getTransferRecord(TreeMap<String, Object> map){
        addSubscribe(mModel.getTransferRecord(map)
                .compose(RxUtils.<CommonList<RechargeRecord>>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<CommonList<RechargeRecord>>(mView) {
                    @Override
                    public void onNext(CommonList<RechargeRecord> data) {
                        mView.onGetRechargeRecordSuccess(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (e instanceof ApiException){
                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)){
                                mView.onGetRechargeRecordSuccess(null);
                                return;
                            }
                        }
                        mView.onGetRechargeRecordFailed();
                        super.onError(e);
                    }
                }));
    }

}
